package itbour.onetouchshow.fragment.challengezone;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.util.Log;

import com.lsjr.callback.EncryBeanCallBack;
import com.lsjr.utils.HttpUtils;

import java.util.HashMap;

import itbour.onetouchshow.base.mvp.BasePresenterImpl;
import itbour.onetouchshow.constants.AppConfig;
import itbour.onetouchshow.utils.DeviceUtil;
import itbour.onetouchshow.utils.L_;
import itbour.onetouchshow.utils.UIUtils;


public class ChallengeZoneListPresenter extends BasePresenterImpl<ChallengeZoneListContract.View> implements ChallengeZoneListContract.Presenter {
    public void getHomepageInfo() {
        HashMap<String, Object> requestHashMap = new HashMap<>();
        requestHashMap.put("device", "610");
        String appVersionName = DeviceUtil.getAppVersionName(UIUtils.getContext());
        requestHashMap.put("appVer", appVersionName);
        Log.e("tag", requestHashMap.toString());
        HttpUtils.getInstance().executeGet(AppConfig.GETAPPHOMEPAGEINFO_V1_3, requestHashMap, new EncryBeanCallBack() {
            @Override
            protected void onXError(String exception) {
                L_.i("response  homepageInfo===" + exception);
                if (mvpView != null) {
                    mvpView.loadFaild(exception);
                }
            }

            @Override
            protected void onSuccess(String response) {
                L_.i("response  homepageInfo===" + response);
                if (mvpView != null) {
                    mvpView.loadSucceed(response);
                }
            }
        });
    }

    /**
     * 获取版本号
     *
     * @return 当前应用的版本号
     */
    private String getVersion(Context context) {
        try {
            PackageManager manager = context.getPackageManager();
            PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0);
            String version = info.versionName;
            return version;
        } catch (Exception e) {
            e.printStackTrace();
            L_.e("获取版本号异常");
            return "";
        }
    }
}
